package com.heaboy.shiwu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserServiceImpl implements UserService {
      TransactionManager transactionManager;

    public UserServiceImpl(TransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    @Override
    public void saveUser() throws Exception {
        try (Connection conn = transactionManager.getConnection();
             PreparedStatement stmt = conn.prepareStatement("INSERT INTO users(name) VALUES(?)")) {
            stmt.setString(1, "张三");
            stmt.executeUpdate();
            System.out.println("保存用户成功");
        }
    }

    @Override
    public void queryUser() {
        System.out.println("查询用户信息");
    }
}

